package com.pml.dao.impl;

import com.pml.dao.IUserDAO;
import com.pml.vo.User;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class UserDAOImpl implements IUserDAO{
    private Connection conn=null;
    private PreparedStatement preparedStatement=null;

    public UserDAOImpl(Connection conn){
        this.conn=conn;
    }

    @Override
    public boolean findUser(User user) throws Exception{
        boolean flag=false;
        String sql="SELECT name FROM user WHERE userId=? and password=? ";
        preparedStatement=conn.prepareStatement(sql);
        preparedStatement.setString(1,user.getUserId());
        preparedStatement.setString(2,user.getPassword());
        ResultSet resultSet=preparedStatement.executeQuery();
        if (resultSet.next()){
            user.setName(resultSet.getString(1));
            flag=true;
        }
        return flag;
    }
}
